﻿using System.Windows.Forms;

namespace GeoSketch2.Core
{
    /// <summary>
    /// The parent class for the capture tools
    /// A capture tool, is a tool that improves functionnalities for other tools, such as a snap tool for a polyline drawing tool
    /// </summary>
    public class BaseCaptureTool:BaseTool
    {
        #region Fields
        /// <summary>
        /// The mouse button of the captured tool
        /// </summary>
        protected MouseButtons MouseButtonCapturedTool;

        /// <summary>
        /// The captured tool
        /// </summary>
        public BaseTool CapturedTool; 
        #endregion

        #region Constructor
        /// <summary>
        /// The parent class for the capture tools
        /// A capture tool, is a tool that improves functionnalities for other tools, such as a snap tool for a polyline drawing tool
        /// </summary>
        /// <param name="Viewport">The current viewport of the tool</param>
        /// <param name="MouseButtonCapturedTool">The mouse button of the captured tool</param>
        /// <param name="Name">The name of the tool</param>
        public BaseCaptureTool(BaseViewport Viewport, MouseButtons MouseButtonCapturedTool, string Name)
            : base(Viewport, Name)
        {
            this.MouseButtonCapturedTool = MouseButtonCapturedTool;

            if (MouseButtonCapturedTool == MouseButtons.Left)
            {
                this.CapturedTool = Viewport.DisplayControl.LeftClicTool;
            }
            else if (MouseButtonCapturedTool == MouseButtons.Right)
            {
                this.CapturedTool = Viewport.DisplayControl.RightClicTool;
            }

            if (this.CapturedTool.GetType().BaseType == typeof(BaseCaptureTool))
            {
                this.CapturedTool = ((BaseCaptureTool)this.CapturedTool).CapturedTool;
            }
        } 
        #endregion

        #region Inputs
        /// <summary>
        /// The method called when a point in object coordinates is sent to the tool
        /// </summary>
        public override void ExternalPointSent(Point2D64D Point)
        {
            this.CapturedTool.ExternalPointSent(Point);
        }

        /// <summary>
        /// The method called when a text is sent to the tool
        /// </summary>
        public override void TextEntry(string Text)
        {
            this.CapturedTool.TextEntry(Text);
        } 
        #endregion
        
        #region Methods
        /// <summary>
        /// Restores the captured tool to be the active tool
        /// </summary>
        public void RestoreCapturedTool()
        {
            if (MouseButtonCapturedTool == MouseButtons.Left)
            {
                Viewport.DisplayControl.LeftClicTool = CapturedTool;
            }
            else if (MouseButtonCapturedTool == MouseButtons.Right)
            {
                Viewport.DisplayControl.RightClicTool = CapturedTool;
            }
        }

        /// <summary>
        /// Draw the graphics requested by the object
        /// </summary>
        public override void Draw()
        {
            this.CapturedTool.Draw();
        }
        #endregion
    }
}
